#include<iostream>
#include<stdio.h>
#include<queue>
#include<algorithm> 
using namespace std;
int Find(int e,int count,int s[]);
int main()
{
	int n,count=1,i,e,x,j,flag;
	queue<int> q;  
	cin>>n;	
	int s[n]={0};
	for(i=0;i<n;i++)
	{
		cin>>x;
		q.push(x);
	}
	e=q.front();
	s[count]=e;
	q.pop();
	while(!q.empty())
	{
		e=q.front();
		flag=Find(e,count,s);	
		if(flag)
		{
			s[flag]=e;
			q.pop();
		}
		else
		{
			count++;
			s[count]= q.front()=e;
			q.pop();
		}
	}
	cout <<count;
} 
int Find(int e,int count,int s[])
{
	int low=1,high=count,mid;
	while(low<=high)
	{
		mid=(low+high)/2;
		if(e>=s[mid])
		low=mid+1;
		else
		high=mid-1;
	}
	if(low>count)return 0; 
	return low;
}
   
